package com.leetcode;

import com.leetcode.common.TreeNode;

/**
 * 965. 单值二叉树
 * 稍微不一样的写法
 *
 * @author fy
 * @date 2022/5/24 8:30
 */
public class Solution965_1 {

    public boolean isUnivalTree(TreeNode root) {
        if (root == null) {
            return true;
        }
        if (root.left != null) {
            if (root.left.val != root.val || !isUnivalTree(root.left)) {
                return false;
            }
        }
        if (root.right != null) {
            if (root.right.val != root.val || !isUnivalTree(root.right)) {
                return false;
            }
        }
        return true;
    }

}
